//
//  RNOLQuickRechargeView.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/26.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLQuickRechargeView.h"
#import "RNOLBankCardView.h"
#import "RNOLNumPadKeyboardView.h"

@interface RNOLQuickRechargeView ()<RNOLNumPadKeyboardProtocol,UITextFieldDelegate>

@property (nonatomic,strong) RNOLNumPadKeyboardView *payPwdInputView;

@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;

@property (weak, nonatomic) IBOutlet UITextField *rechargeMoneyTextField;
@property (weak, nonatomic) IBOutlet UITextField *payPasswordTextField;
@property (weak, nonatomic) IBOutlet UITextView *tipTextView;

@end


@implementation RNOLQuickRechargeView
- (RNOLNumPadKeyboardView *)payPwdInputView{
	if (!_payPwdInputView) {
		_payPwdInputView = [RNOLNumPadKeyboardView FromXIB];
		_payPwdInputView.delegate = self;
	}
	return _payPwdInputView;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    // 设置字体的行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 5;
    NSDictionary *attributes = @{
                                 NSFontAttributeName : KFontSize(12),
                                 NSParagraphStyleAttributeName: paragraphStyle,
																 NSForegroundColorAttributeName : kTextLightGrayColor
                                 };
    self.tipTextView.attributedText = [[NSAttributedString alloc] initWithString: self.tipTextView.text attributes: attributes];
//设置自定义键盘
	self.payPasswordTextField.inputView =  self.payPwdInputView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = KWhiteColor;
        [self addChildViews];
    }
    return self;
}

- (void)addChildViews{
    //顶部的分割线
    UIView *topBg = [RNOLUnitTool createViewWithBackgroundColor: kBgColor];
    topBg.frame = CGRectMake(0, 0, KWIDTH , 15);
    [self addSubview: topBg];
    
    //银行卡
    UIView *cardBg = [RNOLUnitTool createViewWithBackgroundColor:KWhiteColor];
    cardBg.frame = CGRectMake(0, 15, KWIDTH , 180);
    RNOLBankCardView *cardView = [RNOLBankCardView FromXIB];
    cardView.frame = CGRectMake(0, 10, 330 , 160);
    cardView.centerX = cardBg.centerX;
    [cardBg addSubview: cardView];
    [self addSubview: cardBg];
    
    //加载剩下的表单控件
     UIView *bgView = [RNOLUnitTool createViewWithBackgroundColor:KWhiteColor];
    bgView.frame = CGRectMake(0, CGRectGetMaxY(cardBg.frame), KWIDTH , 500);
    UIView *rechargeView = [RNOLQuickRechargeView FromXIB];
    rechargeView.frame = bgView.bounds;
    [bgView addSubview: rechargeView];
    [self addSubview: bgView];

}


//忘记密码
- (IBAction)forgetPasswordAction:(UIButton *)sender {
    
}

//充值
- (IBAction)rechangeAction:(UIButton *)sender {

}


#pragma mark- <RNOLNumPadKeyboardProtocol>
-(void)rnol_keyboardInputDidEnd:(NSString *)text{
	if ([self.payPasswordTextField isFirstResponder]) {
		self.payPasswordTextField.text = self.payPwdInputView.inputText;
	}
}

- (void)rnol_keyboardInputComeplete{
		//完成
	[self.payPasswordTextField resignFirstResponder];
}

- (void)rnol_keyboardInputDeleteBackSpace{
	if ([self.payPasswordTextField isFirstResponder]) {
		if (self.payPwdInputView.inputText.length <= 0) {
			return;
		}
		[self.payPwdInputView.inputText deleteCharactersInRange:NSMakeRange([self.payPwdInputView.inputText length] - 1, 1)];
		self.payPasswordTextField.text =  self.payPwdInputView.inputText;
	}
}

#pragma mark- <UITextFieldDelegate>
- (BOOL)textFieldShouldClear:(UITextField *)textField{
		//监听clear button清空事件
	if ([self.payPasswordTextField isFirstResponder]) {
		self.payPwdInputView.inputText = nil;
	}
	return YES;
}

@end
